﻿// -----------------------------------------------------------------------
// <copyright file="BookmarkTests.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace CloudNinja.Metering.Tests
{
    using System;

    using CloudNinja.Metering.Common.Logging;
    using CloudNinja.Metering.Providers;
    using CloudNinja.Metering.Providers.WebRole;

    using Moq;

    using Xunit;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class BookmarkTests
    {
        [Fact]
        public void CanWriteBookmark()
        {
            var loggerMock = new Mock<ILogger>();
            loggerMock.Setup(l => l.LogException(It.IsAny<Exception>()));
            loggerMock.Setup(l => l.LogError(It.IsAny<string>()));
            loggerMock.Setup(l => l.LogInformation(It.IsAny<string>()));

            var bookMarkRepository =
                new AzureStorageParserBookmarkRepository(
                    GlobalTestSettings.TestStorageConnectionString, loggerMock.Object);
            var now = DateTime.UtcNow;
            var blobUrlString =
                "https://cnm.blob.core.windows.net/wad-iis-logfiles/2c36031c33a2472ab0ab529b5f9e10e8/CloudNinja.Metering.Web/CloudNinja.Metering.Web_IN_0/Web/W3SVC1273337584/u_ex12050109.log";
            bookMarkRepository.SetBookmark(
                new ParserBookmark(
                    "test",
                    blobUrlString,
                    now,
                    10));

            var bookmark = bookMarkRepository.GetBookmark(
                "test",
                blobUrlString);

            Assert.Equal(blobUrlString, bookmark.LogName);
            Assert.Equal(10, bookmark.LastLineParsed);
        }
    }
}
